<?php
namespace app\beautiful\model\mall;
use app\common\model\CommonModel;

class FlashSaleGoodsModel extends CommonModel{
    protected  $name = 'beautiful_goods_flash_sale';
    protected  $pk   = 'flash_sale_goods_id';

    public function goods()
    {
        return $this->hasOne(GoodsModel::class,'goods_id','goods_id');
    }

    public function getFlashSaleTimeAttr($value,$data)
    {
        return [$data['start_time'],$data['end_time']];
    }

    public function getFlashSaleDjsAttr($value,$data)
    {
        $end_time_unix=strtotime($data['end_time']." 23:59:59");
        return $end_time_unix>time() ? $end_time_unix-time() : 0;
    }

    public function getFlashSaleProgressAttr($value,$data)
    {
        return (round($data['fictitious_take_count']/($data['fictitious_take_count']+$data['quota']),2)*100)."%";
    }
}
